package com.tt.service;

import com.tt.entity.User;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;

import static org.mockito.Mockito.doReturn;


@RunWith(MockitoJUnitRunner.class)
class MockServiceTest2 {

    @InjectMocks
    private MockService2 mockService2;
    @Mock
    private MockServiceBase mockServiceBase;

    @BeforeEach
    void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    void add114514() {
        int x = 4;
//        when(mockServiceBase.mockTestInt()).thenReturn(1);
        doReturn(114514).when(mockServiceBase).mockTestInt();
        int result = mockService2.add114514(x);
        Assert.assertEquals(result, Math.addExact(x, 114514));
    }

    @Test
    void testAdd114514() {
        String str = "3";
        Mockito.when(mockServiceBase.MockTestString()).thenReturn("你好");
        doReturn("你好").when(mockServiceBase).MockTestString();
        String result = mockService2.add114514(str);
        Assert.assertEquals(result, "3你好");

    }

    @Test
    void testAdd1145141() {
        User u = new User(1, "1");
        doReturn(u).when(mockServiceBase).MockTestUser();

        User user = mockService2.add114514(u);
        Assert.assertEquals(u, new User(2, "11"));



    }






}





